//
//  SEExamineEntranceBtnView.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/8.
//

import UIKit

enum SEExamineEntranceBtnViewType: Int {
    case reserve = 100
    case scan
    case record
}

@IBDesignable class SEExamineEntranceBtnView: UIView {

    var examineEntranceBtnViewTapClosure: ((_ type: SEExamineEntranceBtnViewType) -> Void)?

    var viewType: SEExamineEntranceBtnViewType = .reserve

    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!

    @IBInspectable var image: UIImage? {
        get {
            return imageView.image
        }
        set {
            imageView.image = newValue
        }
    }

    @IBInspectable var title: String? {
        get {
            titleLabel.text
        }
        set {
            titleLabel.text = newValue
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setUI()
    }

    func setUI() {
        loadNib()

        let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        addGestureRecognizer(tap)
    }

    @objc func tapAction() {
        examineEntranceBtnViewTapClosure?(viewType)
    }

    func loadNib() {
        let view = UINib.init(nibName: String(describing: type(of: self)), bundle: Bundle(for: type(of: self))).instantiate(withOwner: self, options: nil).last as! UIView
        view.frame = bounds
        addSubview(view)
    }
}
